import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class Demo5ArrayList {

    public static void main(String[] args) {

        ArrayList arrayList=new ArrayList<>();

        //1添加元素
        Student s1=new Student("刘德华",20);
        Student s2=new Student("蒋恬",21);
        Student s3=new Student("陈海",22);

        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);

        System.out.println("元素个数："+arrayList.size());

        System.out.println(arrayList);
        //2删除元素
        arrayList.remove(new Student("刘德华",20));

        System.out.println(arrayList);
        //3遍历元素

        System.out.println("-----------------使用迭代器遍历-----------------");
        Iterator iterator= arrayList.iterator();

        while (iterator.hasNext())
        {
            System.out.println(iterator.next());
        }

        ListIterator listIterator=arrayList.listIterator();
        System.out.println("-----------------使用列表迭代器遍历-----------------");
        while (listIterator.hasNext())
        {
            System.out.println(listIterator.next());
        }
        //4判断

        System.out.println(arrayList.contains(new Student("陈海",22)));

    }
}
